﻿



Imports System.Data.OleDb
Imports System.Xml
Imports System.Text
Public Class RSS
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentType = "application/rss+xml"
        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("rss")
        objX.WriteAttributeString("version", "2.0")
        objX.WriteStartElement("channel")

        Dim cmd As New OleDbCommand("SELECT [ID], [RestaurantName], [MichelinStars], [RestaurantPicture], [RestaurantAddress] FROM [Restaurants]", New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString))
        cmd.Connection.Open()
        Dim dr As OleDbDataReader = cmd.ExecuteReader()

        objX.WriteElementString("title", "Restaurant Name")
        objX.WriteElementString("link", "http://localhost:4200/List.aspx")
        objX.WriteElementString("description", "London Itelian Restaurant !")
        objX.WriteElementString("language", "en-us")
        objX.WriteElementString("ttl", "60")
        objX.WriteElementString("lastBuildDate", String.Format("{0:R}", DateTime.Now))

        Do While dr.Read()
            objX.WriteStartElement("item")
            objX.WriteElementString("title", dr("RestaurantName").ToString())
            objX.WriteElementString("RestaurantAddress", dr("RestaurantAddress").ToString())
            objX.WriteElementString("MichelinStars", dr("MichelinStars").ToString())
            objX.WriteStartElement("guid")
            objX.WriteAttributeString("isPermaLink", "true")
            objX.WriteString("http://localhost:4200/Details.aspx?ID=" & dr("ID").ToString())
            objX.WriteEndElement()
            objX.WriteEndElement()
        Loop

        objX.WriteEndElement()
        objX.WriteEndElement()
        objX.WriteEndDocument()
        objX.Flush()
        objX.Close()
        Response.End()
    End Sub

End Class